#define DBC_CHECK_PRECONDITION

using System;
using System.Xml;

using DesignByContract;

namespace Outcoding.GraphGenerator.Entities.XmlBuilders {
    public class PointXmlBuilder : IXmlBuilder {
        
        private Point mResultObject = null;

        public Point ResultObject {
            get {
                return mResultObject;
            }
        }

        public PointXmlBuilder(XmlNode pointXmlNode) {
            Check.Require(pointXmlNode != null, "Xml source node cannot be null");
            Check.Require(pointXmlNode.Name.CompareTo(XmlTagNames.point.ToString()) == 0, 
                "A Point Xml node must be supplied.");
            this.BuildObject(pointXmlNode);
        }

        private void BuildObject(XmlNode pointXmlNode) {
            mResultObject = new Point();
            try {
                mResultObject.Value = ParseValue(pointXmlNode);
            } catch (DesignByContract.PreconditionException preExc) {
                //log error
                mResultObject = null;
                throw;
            }
        }

        private double ParseValue(XmlNode pointXmlNode) {
            return Double.Parse(pointXmlNode.InnerText);
        }
    }
}
